//
//  ClassificationView.m
//  LocalGoods2
//
//  Created by Feihong Ye on 2018/10/23.
//  Copyright © 2018年 Xiaodong Huang. All rights reserved.
//

#import "ClassificationView.h"
#import "Header.h"


@interface ClassificationView ()
@property (nonatomic, weak) UIView *lineView;
@property (nonatomic, strong) NSArray *btnArr;
@end

@implementation ClassificationView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI {
    
    self.btnArr = @[@"平台介绍", @"新人福利", @"安全保障", @"安全保障"];
    NSArray *btnTitleArr = @[@"新品", @"高货", @"特价", @"工艺"];
    for (NSInteger i = 0; i < self.btnArr.count; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(SCREAM_WEIGHT/_btnArr.count * i, 0, SCREAM_WEIGHT/_btnArr.count, SCREAM_WEIGHT/5)];
        [btn setImage:image(_btnArr[i]) forState:UIControlStateNormal];
        [btn setTitle:btnTitleArr[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [btn buttonMixingImagePictureLocation:pictureLocationTop spacing:0];
        btn.tag = i;
        [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
    
    /*
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(SCREAM_WEIGHT/_btnArr.count/4, SCREAM_WEIGHT/_btnArr.count+5, SCREAM_WEIGHT/_btnArr.count/2, 2)];
    self.lineView = lineView;
    lineView.backgroundColor = [UIColor orangeColor];
    [self addSubview:lineView];
     */
    
}

- (void)buttonClick:(UIButton *)sender {
    /*
    [UIView animateWithDuration:0.25 animations:^{
        self.lineView.frame = CGRectMake(SCREAM_WEIGHT/self.btnArr.count/4+sender.tag*SCREAM_WEIGHT/self.btnArr.count, SCREAM_WEIGHT/self.btnArr.count+5, SCREAM_WEIGHT/self.btnArr.count/2, 2);
    }];
     */
    if (self.delegate && [self.delegate respondsToSelector:@selector(classificationViewWithClass:AndButtonTag:)]) {
        [self.delegate classificationViewWithClass:self AndButtonTag:sender];
    }
    
}

@end
